#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
const LL mod=1e9+7;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
map<LL,LL>map1;
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL t;cin>>t;
   while(t--){
      map1.clear();
      string s;cin>>s;
      LL n=s.size();
      LL m;cin>>m;
      for(LL i=0;i<s.size();i++){
          map1[(s[i]-'0')]++;
      }
//      LL k=m/10;
//      m%=10;
      for(LL i=1;i<=m;i++){
          map<LL,LL>map2;
          for(auto j:map1){
              LL temp=j.first;
              temp++;
              if(temp==10){
                 map2[1]=(map2[1]%mod+j.second%mod)%mod;
                 map2[0]=(map2[0]%mod+j.second%mod)%mod;
              }
              else{
                 map2[temp]=(map2[temp]%mod+j.second%mod)%mod;;
              }
          }
          map1.clear();
          for(auto j:map2){
              map1[j.first]=j.second%mod;
          }
      }
      LL ans=0;
      for(auto i:map1){
         ans=(ans%mod+i.second%mod)%mod;
      }
      cout<<ans<<"\n";
   }
   return 0;
}
